FROM golang:1.15-alpine3.12 AS builder

WORKDIR /build
RUN adduser -u 10001 -D app-runner

ENV GOPROXY https://goproxy.cn

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -a -o webapp .

FROM alpine:3.12 AS final
LABEL REPOSITORY="WEBAPP" TAG="v1.0.0"
ENV GIN_MODE=release
WORKDIR /app
COPY --from=builder /build/webapp /app/
#COPY --from=builder /build/config /app/config
COPY --from=builder /etc/passwd /etc/passwd

USER app-runner
ENTRYPOINT ["/app/webapp"]